#include "../mqserver/mq_msgqueue.hpp"
#include "gtest/gtest.h"
#include <iostream>

mymq::MsgQueueManager::Ptr ques;

class QueueTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        ques = std::make_shared<mymq::MsgQueueManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        ques->Destory();
        std::cout << "最后的清理！！\n";
    }
};
// TEST(queue_test,insert_test)
// {
//     std::unordered_map<std::string,std::string> map= {{"k1","v1"}};
//     ques->DeclareQueue("queue1",true,false,false,map);
//     ques->DeclareQueue("queue2",true,false,false,map);
//     ques->DeclareQueue("queue3",true,false,false,map);
//     ASSERT_EQ(ques->size(),3);
// }
TEST(queue_test, select_test) {

    ASSERT_EQ(ques->exists("queue1"), false);
    ASSERT_EQ(ques->exists("queue2"), false);
    ASSERT_EQ(ques->exists("queue3"), true);
    mymq::MsgQueue::Ptr exp = ques->SelectExchange("queue3");
    //ASSERT_NE(exp.get(), nullptr);
    ASSERT_EQ(exp->name, "queue3");
    ASSERT_EQ(exp->durable, true);
    ASSERT_EQ(exp->exclusive, false);
    ASSERT_EQ(exp->auto_delete,false);
    ASSERT_EQ(exp->GetArgs(), std::string("k1=v1&"));
}
TEST(queue_test, remove_test) {
    ques->DeleteMsgQueue("queue3");
    mymq::MsgQueue::Ptr exp = ques->SelectExchange("queue3");
    ASSERT_EQ(exp.get(), nullptr);
    ASSERT_EQ(ques->exists("queue3"), false);
}
int main(int argc, char *argv[])
{
    testing::AddGlobalTestEnvironment(new QueueTest);
    testing::InitGoogleTest(&argc,argv);
    RUN_ALL_TESTS();
    return 0;
}
